package cn.edw.swu.bc.lessonfive

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class BasketballPlayerAdapter (val basketballPlayer: ArrayList<BasketballPlayer>) : RecyclerView.Adapter<BasketballPlayerAdapter.BasketballPlayerViewHolder>() {

    inner class BasketballPlayerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val name = itemView.findViewById<TextView>(R.id.name)
        val desc = itemView.findViewById<TextView>(R.id.description)
        val img =  itemView.findViewById<ImageView>(R.id.avatar)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BasketballPlayerViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_basketball_player,parent,false)
        val holder = BasketballPlayerViewHolder(view)
        return holder
    }

    override fun onBindViewHolder(holder: BasketballPlayerViewHolder, position: Int) {
        val teacher = basketballPlayer[position]
        holder.name.text = teacher.name
        holder.desc.text = teacher.description
        holder.img.setImageResource(teacher.avatar)
    }

    override fun getItemCount(): Int {
        return basketballPlayer.size
    }
}